package department.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import department.dao.DepartmentDAO;
import department.domain.Department;
import department.service.DepartmentService;

public class DepartmentListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		1. 요청파라터 조회 (X)
//		2. 업무로직 처리 - 전체 부서 정보를 조회 : service.selectDepartmentList() : ArrayList
		DepartmentService service = DepartmentService.getInstance();//DAO 객체 조회
		
		String url = null;
		try {
			ArrayList<Department> list = service.getDepartmentList();
			request.setAttribute("list", list);
			url = "/department_list.jsp";
		} catch (SQLException e) {
			e.printStackTrace();
			request.setAttribute("error_message", e.getMessage());
			url = "/error.jsp";
		}
		RequestDispatcher rdp = request.getRequestDispatcher(url);
		rdp.forward(request, response);

	}

}








